/*************************************************
Author: byron
Date: 04/08/2013
Description:
Notes: 
*************************************************/

#ifndef __CBattleBuff_h__
#define __CBattleBuff_h__

#include "../skill/CSkillEffect.h"

class CBattleBuff
{
public:
    CBattleBuff() 
    {
        Clear();
    }

    void Clear()
    {
        _iTurn = 0;
        _iSrcRoleID = -1;
        _stEffect.Clear();
        _aiBuffLast.Clear();
    }

    virtual ~CBattleBuff() 
    {
    }

    bool IsSwim() const
    {
        return _stEffect.IsSwim();
    }

    bool IsStick() const
    {
        return _stEffect.IsStick();
    }

    bool IsShield() const 
    {
        return _stEffect.IsShield();
    }

    unsigned int GetID() const {return _stEffect.GetID();}
    unsigned char GetStatType() const {return _stEffect.GetStatType();}
    unsigned char GetSubType() const {return _stEffect.GetSubType();}
    int GetData() const {return _stEffect.GetData();}
    int GetMaxTurn();
    int GetTurn() const {return _iTurn;}
    int GetSrcRoleID() const {return _iSrcRoleID;}
    int GetLastSize() const {return _aiBuffLast.Size();}
    CSkillEffect& GetSkillEffect(){return _stEffect;}

    void SetTurn(int iTurn){_iTurn = iTurn;}
    void SetSrcRoleID(int iSrcID, int iLast);
    void SetSkillEffect(CSkillEffect& stEffect){_stEffect = stEffect;}
    void SetData(int iVal) {_stEffect.SetData(iVal);}

    void NewTurn();
    void AddOneLast(int iLast);
    void SetOneBuff(CSkillEffect& stSkillEffect, int iSrcID);

    int DealShieldBuff(int iRoleID, int& iChgBlood);

    void DumpBattleBuff();

private:
    int              _iTurn; //获得的回合次序
    int              _iSrcRoleID; //来源角色ID 当前按照回合数最高的进行替换 如果回合数相同保证先入原则
    CSkillEffect     _stEffect; //保存实体
    CTLib::CTArray<int, MAX_BATTLE_BUFF_LAST_COUNT>  _aiBuffLast;//数量表示叠加层数而值表示递减的回合数
};

class CBattleBuffList
{
public:
    typedef CTLib::CTArray<CBattleBuff, MAX_BATTLE_BUFF_COUNT> BATTLE_BUFF_LIST;

    enum BATTLE_BUFF_SOURCE_TYPE
    {
        BATTLE_BUFF_SOURCE_SELF = 1,    //来源于自身
        BATTLE_BUFF_SOURCE_TEAM = 2,    //来源于队友
        BATTLE_BUFF_SOURCE_ENEMY = 3,   //来源于敌人
    };

    CBattleBuffList() 
    {
        Clear();
    }

    void Clear()
    {
        _astSelfBuff.Clear();
        _astTeamBuff.Clear();        
        _astEnemyBuff.Clear();
    }

    virtual ~CBattleBuffList() 
    {
    }

    int GetFrontIndex(int iSrcType, int iIndex);

    void RoleAddBuffVideo(int iRoleID, unsigned int uiEffectID, int iSrcType,
            int iSrcID, int iIndex, int iAddNum);

    void RoleDelBuffVideo(int iRoleID, unsigned int uiEffectID, int iSrcType,
            int iSrcID, int iIndex);

    void RoleChgBuffVideo(int iRoleID, unsigned int uiEffectID, int iSrcType,
            int iSrcID, int iIndex);

    int AddOneBuff(int iRoleID, CSkillEffect& stSkillEffect, int iSrcType,
            int iSrcID, BATTLE_BUFF_LIST& stBuffList);

    int AddOneBuff(int iRoleID, CSkillEffect& stSkillEffect, int iSrcType,
            int iSrcID);

    bool IsSwim();

    bool IsStick();

    bool InDefinitBuff(unsigned char ucStatType, unsigned char ucSubType);

    bool InDefinitSubBuff(unsigned char ucStatType, unsigned char ucSubType,
            int iData);

    int DealShieldBuff(int iRoleID, int& iChgBlood);

    int DelBuffByStatType(int iRoleID, int iSrcType, unsigned char ucStatType,
            BATTLE_BUFF_LIST& stBuffList);

    int DelBuffByStatType(int iRoleID, unsigned char ucStatType);

    int DelBuffBySubType(int iRoleID, int iSrcType, unsigned char ucStatType,
            unsigned char ucSubType, BATTLE_BUFF_LIST& stBuffList);

    int DelBuffBySubType(int iRoleID, unsigned char ucStatType,
            unsigned char ucSubType);

    int DelAllBuff(int iRoleID, int iSrcType, BATTLE_BUFF_LIST& stBuffList);

    void DelAllBuff(int iRoleID);

    void NewTurn(int iRoleID, int iSrcType, BATTLE_BUFF_LIST& stBuffList);

    void NewTurn(int iRoleID);

    int GetBuffSize();

    CBattleBuff& GetBattleBuff(int iIndex);

    void DumpBattleBuffList(BATTLE_BUFF_LIST& stBuffList);

    void DumpBattleBuffList();

private:
    BATTLE_BUFF_LIST _astSelfBuff;//来源于自身
    BATTLE_BUFF_LIST _astTeamBuff;//来源于队友
    BATTLE_BUFF_LIST _astEnemyBuff;//来源于敌人
};

#endif // __CBattleBuff_h__

